package com.platform.mobile.operator;

import java.util.LinkedHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.platform.base.SysException;
import com.platform.bean.PageInfo;
import com.platform.mobile.bean.PaitentListBean;
import com.platform.mobile.bean.ReqBean;
import com.platform.mobile.bean.ResBean;
import com.platform.mobile.bean.ResultBean;
import com.platform.mobile.bean.SearchPaitentRequest;
import com.platform.mobile.factory.Operator;
import com.platform.mobile.service.PaitentService;

/**
 * 通过姓名或手机号查询病人信息业务处理类
 * @author inven
 *
 */
@Component
public class SearchPaitent extends Operator{

	private static Logger log = LoggerFactory.getLogger(SearchPaitent.class);
	
	@Autowired
	private PaitentService service;
	
	@SuppressWarnings("unchecked")
	@Override
	public ResBean operate(ReqBean reqBean) throws SysException {
		
		log.info("进入到SearchPaitent业务处理类，处理[" + reqBean.getClientInfo() + "]用户请求");
		
		ResBean resBean = new ResBean();
		resBean.setClientInfo(reqBean.getClientInfo());
		resBean.setJsonrpc("2.0");
		resBean.setMethod("SearchPaitent");
		ResultBean result = new ResultBean();
		
		try{
			
			Object params = reqBean.getParams();
			if(params != null){
				
				LinkedHashMap<String, Object> paramMap = (LinkedHashMap<String, Object>)params;
				String content = paramMap.get("content").toString();
				
				LinkedHashMap<String, Object> pageInfoMap
					= (LinkedHashMap<String, Object>)paramMap.get("pageInfo");
				PageInfo pageInfo = new PageInfo();
				pageInfo.setCurrPage((int)pageInfoMap.get("currPage"));
				//pageInfo.setData(pageInfoMap.get("data").toString());
				//pageInfo.setEndPage((int)pageInfoMap.get("endPage"));
				//pageInfo.setOrder(pageInfoMap.get("order").toString());
				pageInfo.setPageSize((int)pageInfoMap.get("pageSize"));
				//pageInfo.setStartPage((int)pageInfoMap.get("startPage"));
				//pageInfo.setState(pageInfoMap.get("state").toString());
				//pageInfo.setTotolPage((int)pageInfoMap.get("totolPage"));
				
				SearchPaitentRequest request = new SearchPaitentRequest();
				request.setContent(content);
				request.setPageInfo(pageInfo);
				
				PaitentListBean bean = service.searchPaitents(request);
				result.setData(bean);
				result.setInfo("查询病人资料信息成功");
				result.setResultStatus("1");
				resBean.setResult(result);
			}
			
		}catch(Exception e){
			e.printStackTrace();
			result.setData(null);
			result.setInfo("查询病人资料信息失败");
			result.setResultStatus("0");
			resBean.setResult(result);
		}
		return resBean;
	}

}
